import axios from 'axios';
import qs from 'qs'
import store from '@/store'
import router from '@/router'

//创建axios实例 
const instance = axios.create()

//针对instance,添加请求拦截器，每个请求都带着token一起发送
// instance.interceptors.request.use(config => {
//   //config对象就是请求配置数据对象
//   let token = store.state.token
//   if (token) {
//     config.headers['Authoization'] = token
//   }
//   return config
// })

const myaxios = {
  get(url: string, params: object) {
    return instance({ url, method: 'GET', params })
  },
  /**
   * 
   * @param {string} url //请求资源路径
   * @param {object} params  //请求参数对象{k:v,k2:v2}
   * @returns Promise
   */
  post(url: string, params: object) {
    return instance({ url, method: 'POST', data: qs.stringify(params) })
  }

}
export default myaxios